﻿#include "SVTemplateModel.h"

SVTemplateModel::SVTemplateModel(QObject *parent)
    : QObject(parent)
{
}

SVTemplateModel *SVTemplateModel::getInstance()
{
    static SVTemplateModel instance;
    return &instance;
}

QList<QImage> SVTemplateModel::getTemplateImages() const
{
    QList<QImage> images;
    for (auto &feature : mTemplateImages) {
        if (!feature.mat.empty()) {
            images.append(convertCVImageToQImage(feature.mat));
        }
    }
    return images;
}

std::vector<PCBTemplateFeatures> SVTemplateModel::getTemplateFeatures() const
{
    std::vector<PCBTemplateFeatures> features;
    for (auto &feature : mTemplateImages) {
        features.push_back(feature);
    }
    return features;
}

void SVTemplateModel::addTemplateImage(const PCBTemplateFeatures &feature)
{
    mTemplateImages.append(feature);
}

void SVTemplateModel::removeTemplateImage(int index)
{
    if (index >= 0 && index < mTemplateImages.size()) {
        mTemplateImages.removeAt(index);
    }
}

void SVTemplateModel::clearTemplateImages()
{
    mTemplateImages.clear();
}
